package com.kxmall.admin.controller.vehicle;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.admin.controller.vehicle.service.IKxVehicleOrderService;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.page.TableDataInfo;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.vehicle.domain.bo.KxVehicleOrderBo;
import com.kxmall.vehicle.domain.vo.KxVehicleBoxGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 餐车订单
 */
@Slf4j
@Api(tags = "餐车订单")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/order/vehicleOrder")
public class KxVehicleOrderController extends BaseController {

    private final IKxVehicleOrderService kxVehicleOrderService;

    /**
     * 查询订单列表
     */
    @SaIgnore
    @ApiOperation(value = "/order/vehicleOrder/listAll - 查询订单列表", httpMethod = "GET")
    @GetMapping("/listAll")
    public R<List<KxVehicleOrderVo>> listAll(KxVehicleOrderBo bo) {
        List<KxVehicleOrderVo> list =  kxVehicleOrderService.queryList(bo);
        log.info(list.toString());
        return R.ok(list);
    }
    /**
     * 分页查询订单列表
     */
    @SaCheckPermission("order:vehicleOrder:pageList")
    @ApiOperation(value = "/order/vehicleOrder/pageList - 分页查询订单列表", httpMethod = "GET")
    @GetMapping("/pageList")
    public TableDataInfo<KxVehicleOrderVo> pageList(KxVehicleOrderBo bo, PageQuery pageQuery) {
        TableDataInfo< KxVehicleOrderVo> infoList =  kxVehicleOrderService.queryPageList(bo, pageQuery);
        log.info(infoList.toString());
        return infoList;
    }
    /**
     * 导出餐车订单列表
     */
    @SaCheckPermission("order:vehicleOrder:export")
    @Log(title = "导出餐车订单列表", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "/order/vehicleOrder/export - 导出餐车订单列表", httpMethod = "POST")
    @PostMapping("/export")
    public void export(KxVehicleOrderBo bo, HttpServletResponse response) {
        List<KxVehicleOrderVo> list = kxVehicleOrderService.queryList(bo);
        log.info(list.toString());
        ExcelUtil.exportExcel(list, "餐车订单列表", KxVehicleOrderVo.class, response);
    }

    /**
     * 获取订单详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("order:vehicleOrder:query")
    @ApiOperation(value = "/order/vehicleOrder/query/{id} - 获取订单详细信息", httpMethod = "GET")
    @GetMapping("/query/{id}")
    public R<KxVehicleOrderVo> query(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        KxVehicleOrderVo kxVehicleOrderVo = kxVehicleOrderService.queryById(id);
        log.info(kxVehicleOrderVo.toString());
        return R.ok(kxVehicleOrderVo);
    }

    /**
     * 修改订单
     */
    //@SaCheckPermission("order:vehicleOrder:edit")
    //@Log(title = "修改订单", businessType = BusinessType.UPDATE)
    //@ApiOperation(value = "/order/vehicleOrder/edit - 修改订单", httpMethod = "POST")
    //@PutMapping("/edit")
    //@RepeatSubmit()
    //public R<Void> edit(@Validated(EditGroup.class) @RequestBody KxVehicleOrderBo bo) {
    //    return toAjax(kxVehicleOrderService.updateByBo(bo));
    //}

    /**
     * 删除订单
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("order:vehicleOrder:remove")
    //@Log(title = "删除订单", businessType = BusinessType.DELETE)
    //@ApiOperation(value = "/order/vehicleOrder/remove/{ids} - 删除订单", httpMethod = "DELETE")
    //@DeleteMapping("/remove/{ids}")
    //public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
    //    return toAjax(kxVehicleOrderService.deleteWithValidByIds(Arrays.asList(ids), true));
    //}

}
